#!/bin/sh

DST_FOLDER=${1}
CLEANUP_REGEX='^(.*/codenvy-data/fs/([0-9a-f]{2}/){3}workspace[0-9a-z]+)$'

hasSudoCommand() {
  hash sudo 2>/dev/null && return 0 || return 1
}

if echo "${DST_FOLDER}" | grep -q -E "${CLEANUP_REGEX}"; then
  if hasSudoCommand; then
    sudo rm -rf "${DST_FOLDER}";
  else
    rm -rf "${DST_FOLDER}";
  fi;
fi
